###   Implementation Constraints on natural climate solutions
###   Author: Kroeger, Timm; Erbaugh, James; Luo, Zhixian; Hilary Brumberg; Waverly Eichhorst; Margaret Hegwood; Anna LoPresti; Priya Shyamsundar; Peter W. Ellis; Lauren E. Oakes; Dow Martin; Pedro H. S. Brancalion; Mieke Bourne; Arundhati Jagadish; Kemen G. Austin; Andrew Kinzer; Marcos Sanjuán; Lisa McCullough; Marta Echavarria,

library(tidyverse)
library(ggplot2)
library(grid)
library(ggpattern)

nbase<-read.csv("NBaseData_v1.csv")

## Fig. S12. Frequency counts of constraint-pathway-location observations by pathway and constraint category
heatmapcounts<-nbase%>%
  group_by(NCS_Pathway, Constraint_category)%>%
  summarize(count=n())%>%
  select(NCS_Pathway, Constraint_category, count)

totals_heatmap<-ggplot(heatmapcounts%>%
                         filter(NCS_Pathway!="other (please specify)" |
                                  NCS_Pathway!="NA"), 
                       aes(x=NCS_Pathway, y=Constraint_category, fill=count))+
  geom_tile() +
  scale_fill_gradient(name="Totals", low = "white", high = "red")+
  coord_flip()+
  theme_classic()+
  ylab(NULL)+xlab(NULL)+
  theme(axis.text.x = element_text(angle = 45, hjust = 1),
        legend.text = element_text(""))
totals_heatmap

ggsave("Fig S12.jpg", totals_heatmap,  width=8, height=8, dpi=720)